package com.duoduo.admin.entity;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Set;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Entity
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
public class SysUser implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1928885717881603040L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	@Column(columnDefinition = "int(11) comment '用户id'")
	private Long userId;
	@Column(columnDefinition = "int(11) comment '部门id'")
	private Long deptId;
	private String username;
	@Column(columnDefinition = "varchar(255) comment '密码'")
	private String password;
	private String phone;
	
	private String avatar;
	
	private String lockFlag;
	/**
	 * 0-正常，1-删除
	 */
	private String delFlag;
	
    @ManyToMany(targetEntity = SysRole.class, fetch = FetchType.LAZY)
    @JoinTable(name = "sys_user_role", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})
    @ToString.Exclude
    private Set<SysRole> authorities = Collections.emptySet();
    
    @ManyToMany(targetEntity = SysRole.class, fetch = FetchType.LAZY)
    @JoinTable(name = "sys_user_post", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "post_id")})
    @ToString.Exclude
    private Set<SysPost> posts = Collections.emptySet();
    
    /**
   	 * 创建人
   	 */
       @CreatedBy
   	private String createBy;
        /**
   	 * 创建时间
   	 */
    @CreatedDate
   	private LocalDateTime createTime;
        /**
   	 * 修改人
   	 */
    @LastModifiedBy
   	private String updateBy;
        /**
   	 * 更新时间
   	 */
    @LastModifiedDate
   	private LocalDateTime updateTime;
}
